package cn.bdqn.pn.service.schedule.impl;

import cn.bdqn.pn.pojo.schedule.Seat;
import cn.bdqn.pn.reposity.schedule.SeatDao;
import cn.bdqn.pn.service.schedule.SeatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.SQLException;
import java.util.List;

@Service("seatService")
public class SeatServiceImpl implements SeatService {

    @Autowired
    private SeatDao seatDao;

    /**
     * 增加座位信息
     * @param seat
     * @return
     * @throws SQLException
     */
    @Override
    public boolean addSeatInfo(Seat seat) throws SQLException {
        Seat seat1 = seatDao.save(seat);
        if(seat1!=null){
            return true;
        }
        return false;
    }

    /**
     * 根据场地id查询座位信息
     * @param placeId
     * @return
     * @throws SQLException
     */
    @Override
    public List<Seat> seatlist(Integer placeId) throws SQLException {
        return seatDao.findSeatByPlace_Placeid(placeId);
    }

    /**
     * 根据座位id查询座位信息
     * @param seatId
     * @return
     * @throws SQLException
     */
    @Override
    public Seat findBySeatId(Integer seatId) throws SQLException {
        return seatDao.findOne(seatId);
    }

    /**
     * 根据座位id修改座位信息
     * @param seat
     * @return
     * @throws SQLException
     */
    @Override
    public boolean updateSeatInfo(Seat seat) throws SQLException {
        if(seatDao.exists(seat.getSeatid())){
            Seat seatResult=seatDao.saveAndFlush(seat);
            return true;
        }
        return false;
    }
}
